package com.fc.tms.action;

import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.fc.framework.action.AbstractAction;
import com.fc.tms.entity.User;
import com.fc.tms.filter.UserFilter;
import com.fc.tms.service.UserService;

@Controller
@RequestMapping("/userAll")
public class UserAllAction extends AbstractAction {
    @Resource
    UserService userService;

    @RequestMapping(method = RequestMethod.GET)
    public String index(Model model, HttpServletRequest request) {
        model.addAttribute("filter", new UserFilter());

        return Pages.USER_ALL_LIST;
    }

    @RequestMapping(value = "/query", method = RequestMethod.POST)
    public String list(Model model, HttpServletRequest request, @ModelAttribute UserFilter filter)
                                                                                                  throws ParseException {
        List<User> userList = userService.find(filter);
        
        model.addAttribute("userList", userList);
        model.addAttribute("filter", filter);
        
        return Pages.USER_ALL_LIST;
    }
}
